import 'package:flutter/material.dart';
import 'package:reabampos/src/reabam/operation/rb_config.dart';
import 'package:xsdk_flutter/xsdk/xsdk_flutter_package.dart';

/*
测试serverSocket
 */
class CustomReSetH5WebUtlStatePage extends XState {
  late String h5Url_sp;
  late String secondScreenWebUrl_sp;

  XFunctionResultCallback<String> onCallbackResult;

  CustomReSetH5WebUtlStatePage(this.onCallbackResult);

  @override
  void onCreate() {
    //'https://global-pos.reabam.com/hk'
    //http://fat-global-pos.reabam.com:58090/hk   C180
    h5Url_sp = XSharePreferencesUtils.getString(RBConfigs.SP_CustomH5Url);
    secondScreenWebUrl_sp =
        XSharePreferencesUtils.getString(RBConfigs.SP_CustomSecondScreenWebUrl);
  }

  @override
  void onStart() {}

  @override
  Future<void> updateData({int pageIndex = 1}) async {}

  @override
  Widget onBuild(BuildContext context) {
    return XWidgetUtils.getXLayoutRoundedRect(
        width: 350,
        height: 280,
        child: XWidgetUtils.getLayoutColumn(children: [
          XWidgetUtils.getWidgetText('主屏Url地址:',
              style: XStyleUtils.textStyle_666_14(),
              padding: XWidgetUtils.getEdgeInsets(0, 10, 0, 5)),
          XWidgetUtils.getWidgetTextField(
              hintText: '输入主屏Url',
              initialValue: h5Url_sp,
              onChanged: (res) {
                h5Url_sp = res;
              }),
          XWidgetUtils.getLayoutContainer(height: 10),
          XWidgetUtils.getWidgetDivider(marginRight: 0, marginLeft: 0),
          XWidgetUtils.getWidgetText('副屏Url地址:',
              style: XStyleUtils.textStyle_666_14(),
              padding: XWidgetUtils.getEdgeInsets(0, 10, 0, 5)),
          XWidgetUtils.getWidgetTextField(
              hintText: '输入副屏Url',
              initialValue: secondScreenWebUrl_sp,
              onChanged: (res) {
                secondScreenWebUrl_sp = res;
              }),
          Spacer(),
          XWidgetUtils.getWidgetDivider(marginRight: 0, marginLeft: 0),
          XWidgetUtils.getLayoutRow(children: [
            XWidgetUtils.getLayoutExpanded(
                XWidgetUtils.getWidgetGestureDetector(
                    child: XWidgetUtils.getLayoutContainer(
                        backgroundColor: Colors.white,
                        padding: XWidgetUtils.getEdgeInsets(0, 20, 0, 5),
                        alignment: Alignment.center,
                        child: XWidgetUtils.getWidgetText('取消',
                            style: XStyleUtils.textStyle_666_16())),
                    onTap: () {
                      Navigator.of(context).pop();
                    })),
            XWidgetUtils.getLayoutExpanded(
                XWidgetUtils.getWidgetGestureDetector(
                    child: XWidgetUtils.getLayoutContainer(
                        backgroundColor: Colors.white,
                        padding: XWidgetUtils.getEdgeInsets(0, 20, 0, 5),
                        alignment: Alignment.center,
                        child: XWidgetUtils.getWidgetText('确定',
                            style: XStyleUtils.textStyle_000_16())),
                    onTap: () {
                      XSharePreferencesUtils.saveString(
                          RBConfigs.SP_CustomH5Url, h5Url_sp);
                      XSharePreferencesUtils.saveString(
                          RBConfigs.SP_CustomSecondScreenWebUrl,
                          secondScreenWebUrl_sp);

                      onCallbackResult("");
                    })),
          ])
        ]));
  }

  @override
  void onDestroy() {}
}
